<template>
  <view class="padding">
    <view class="title">设置新密码</view>
    <input type="password" v-model="userPasswordDTO.password" placeholder="请输入旧密码" class="input"/>
    <input type="password" v-model="userPasswordDTO.newPass" placeholder="请输入新密码" class="input"/>
    <input type="password" v-model="userPasswordDTO.confirmPassword" placeholder="请确认新密码" class="input"/>
    <view style="font-size: 18px">提示：如果密码是初始密码123456，请修改密码后重新登录</view>
    <button @click="updatePassword" class="btn">确认修改</button>
  </view>
</template>

<script>
import request from '../../util/request';
export default {
  data() {
    return {
		userPasswordDTO:{
			userId:null,
			password:"",
			newPass:"",
			confirmPassword:""
		},
    };
  },
  methods: {
    updatePassword() {
		if (this.userPasswordDTO.password!==''&&this.userPasswordDTO.newPass!==''&&this.userPasswordDTO.confirmPassword!==null){
			if (this.userPasswordDTO.newPass !== this.userPasswordDTO.confirmPassword) {
				uni.showToast({
					title:"两次密码不一致",
					icon:'error'
				})
			  return;
			}else{
				this.userPasswordDTO.userId=this.$store.state.userInfo.id
				console.log(this.userPasswordDTO)
				request.post("/user/password",this.userPasswordDTO).then(res=>{
					if(res.code==="200"){
						uni.showToast({
							title:"修改成功",
							icon:'success'
						})
						// 其他页面的跳转方式
						uni.navigateTo({
							url:"/pages/login/index"
						})
					}else{
						uni.showToast({
							title:res.msg,
							icon:'error'
						})
					}
				})
			}
		}else{
			uni.showToast({
				title:"请填写完整",
				icon:'error'
			})
		}
    }
  }
}
</script>

<style scoped>

.title {
  font-size: 30px;
  margin: 20px 0;
}
.input {
  margin-bottom: 15px;
  padding: 10px;
  border: 1px solid #ccc;
}
.btn {
  background-color: #007aff;
  color: white;
  text-align: center;
  border: none;
}
</style>
